<template>
  <div id="shop-item">
    <div class="item-selector">
      <label class="mdui-checkbox">
        <input type="checkbox" v-model="itemInfo.checked" @click="checkedChange" />
        <i class="mdui-checkbox-icon"></i>
      </label>
    </div>

    <div class="item-img">
      <img :src="itemInfo.image" alt="商品图片">
    </div>
    <div class="item-info">
      <div class="item-title">{{itemInfo.title}}</div>
      <div class="item-desc">商品描述: {{itemInfo.desc}}</div>
      <div class="info-bottom">
        <div class="item-price left">¥{{itemInfo.price}}</div>
        <div class="item-count right">
          <span style="float: left;">x{{itemInfo.count}}</span>

          <div style="float: right;">
            <button class="mdui-btn mdui-btn-icon mdui-btn-dense mdui-color-theme-accent mdui-ripple"><i
                class="mdui-icon material-icons" @click="countremove()">remove_circle</i></button>
            <span>{{itemInfo.count}}</span>
            <button class="mdui-btn mdui-btn-icon mdui-btn-dense mdui-color-theme-accent mdui-ripple"><i
                class="mdui-icon material-icons" @click="countadd()">add_circle</i></button>
          </div>

        </div>

      </div>
    </div>
  </div>
</template>

<style scoped>
  #shop-item {
    width: 100%;
    display: flex;
    font-size: 0;
    padding: 5px;
    border-bottom: 1px solid #ccc;
  }

  .item-selector {
    width: 5%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .item-title,
  .item-desc {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .item-img {
    padding: 5px;
    /*border: 1px solid #ccc;*/
  }

  .item-img img {
    width: 80px;
    height: 100px;
    display: block;
    border-radius: 5px;
  }

  .item-info {
    font-size: 17px;
    color: #333;
    padding: 5px 10px;
    position: relative;
    overflow: hidden;
  }

  .item-info .item-desc {
    font-size: 14px;
    color: #666;
    margin-top: 15px;
  }

  .info-bottom {
    margin-top: 10px;
    position: absolute;
    bottom: 10px;
    left: 10px;
    right: 10px;
  }

  .info-bottom .item-price {
    color: orangered;
  }
</style>

<script>
    import { mapActions } from 'vuex'

  export default {
    name: 'CartListItem',
    //传参：父传子，写法：["形参1"[,"形参2"]]
    props: {
      itemInfo: {
        type: Object,
        default() {
          return {}
        }
      }

    },
    created() {

    },
    mounted() {

    },
    data() {
      return {

      }
    },
    methods: {
      ...mapActions([
        'addCart',
        'removeCart',
      ]),
      checkedChange() {
        this.itemInfo.checked = !this.itemInfo.checked
      },
      countremove() {
        if(this.itemInfo.count >0){
          this.removeCart(this.itemInfo)
        }
        

      },
      countadd() {
        this.addCart(this.itemInfo)
      },

    },
    mixins: [],
    components: {

    },
  }
</script>